﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace cstdx.Proto.Ext;

/// <summary>
/// ExCmd1响应包结构
/// </summary>
public class ExCmd1Response
{
	/// <summary>
	/// 未知用途的字节数据
	/// </summary>
	public byte[] Unknown { get; set; } = Array.Empty<byte>();

	/// <summary>
	/// 响应内容
	/// </summary>
	public string Reply { get; set; } = string.Empty;

	/// <summary>
	/// 从字节数组反序列化响应数据
	/// </summary>
	/// <param name="data">原始响应字节数组</param>
	public void Unmarshal(byte[] data)
	{
		Unknown = data;
		// 截取data[3:53]范围的字节并从UTF8转换为GBK
		if (data.Length >= 53)
		{
			byte[] subData = new byte[50]; // 53-3=50
			Array.Copy(data, 3, subData, 0, 50);
			Reply = Encoding.UTF8.GetString(subData);
			// 注意：原Go代码使用Utf8ToGbk转换，这里根据实际编码需求可能需要调整
			// 如果需要GBK编码，需引用System.Text.Encoding.CodePages并注册
			// Reply = Encoding.GetEncoding("GBK").GetString(subData);
		}
	}
}
